package com.jettech.oa.jbpm.handler;

import org.jbpm.graph.exe.ExecutionContext;
import org.jbpm.jpdl.el.ELException;
import org.jbpm.jpdl.el.impl.JbpmVariableResolver;

import com.jettech.oa.common.ConstType;
import com.jettech.oa.domain.Document;
/**
 * 自定义的Jbpm变量解析器
 * 此变量解析器在jbpm.cfg.xml中jbpm.variable.resolver使用
 * @author Administrator
 *
 */
public class MyJbpmVariableResolver extends JbpmVariableResolver {
	@Override
	public Object resolveVariable(String name) throws ELException {
		/**
		 * doc_是流程定义文件中的变量的前缀
		 */
		if(name.startsWith("doc_")){
			String propertyName = name.substring(4);
			ExecutionContext executionContext = ExecutionContext.currentExecutionContext();
			Long documentId = (Long)executionContext.getContextInstance().getVariable(ConstType.DOCUMENT_ID);
			Document doc = (Document)executionContext.getJbpmContext().getSession().load(Document.class, documentId);
			return doc.getProperty(propertyName);
		}
		return super.resolveVariable(name);
	}

}
